package com.cloud.template.base.mvc;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * 用于拦截全局的Controller的异常，注意：ControllerAdvice注解只拦截Controller不会拦截Interceptor的异常
 * Created by zhenghao on 2018/5/12.
 */
@ControllerAdvice
public class ExeptionHandler {
    @ExceptionHandler(Exception.class)
    public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) {
        ModelAndView mv = new ModelAndView("error");
        mv.addObject("e", e);
        mv.addObject("eName", e.getClass().getName());
        mv.addObject("uri", req.getRequestURI());
        mv.addObject("url", req.getRequestURL());
        return mv;
    }
}
